﻿Imports System.Data.OleDb

Public Class Register
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
        Try

            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)

            Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
            If String.IsNullOrEmpty(continueUrl) Then
                continueUrl = "~/"
            End If
            Dim lastID As Int32 = New aspnet_UsersManagement().SelectTopASPNETUser()
            Dim profilesManagemnt As ProfilesManagement = New ProfilesManagement()
            profilesManagemnt.InsertProfileNewUser(lastID, "Pictures/Avatars/default_user.png")

            Dim myIdCookie As HttpCookie = New HttpCookie("userIdCookie", lastID)
            myIdCookie.Expires = DateTime.Now.AddDays(9)
            Response.Cookies.Add(myIdCookie)

            Dim selectProfile As ProfilesManagement = New ProfilesManagement()
            Dim dr As OleDbDataReader = selectProfile.SelectProfileByUserID(lastID)

            Dim profileId As Int32

            If dr.HasRows Then
                dr.Read()
                If Not IsDBNull(dr("ProfileId")) Then profileId = Convert.ToInt32(dr("ProfileId"))
            End If


            Dim pageName As PagesNamesManagement = New PagesNamesManagement()
            pageName.InsertPageName("ProfileViewer.aspx?ProfileId=" + profileId.ToString())

            Response.Redirect("~/ProfileManager.aspx")

        Catch ex As Exception

        End Try
    End Sub
End Class